// ignore_for_file: deprecated_member_use

import 'package:flutter/material.dart';
import 'package:getx/custom/customappbar.dart';
import 'package:getx/getx/count_getx.dart';
import 'package:getx/fluttergetx/other_page.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:get/get.dart';

// ignore: must_be_immutable
class CountGetX extends StatefulWidget {
  String name;
  CountGetX({Key? key, required this.name}) : super(key: key);
  @override
  _CountGetXState createState() => _CountGetXState();
}

class _CountGetXState extends State<CountGetX> {
  @override
  Widget build(BuildContext context) {
    final Controller controller = Get.put(Controller()); //获取state的值
    return Scaffold(
      appBar: CustomAppbar(widget.name, Theme.of(context).primaryColor),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            CircleAvatar(
              backgroundColor: Theme.of(context).primaryColor,
              child: GetBuilder<Controller>(
                init: Controller(),
                id: 'count', //绑定id刷新 可选
                builder: (Controller c) {
                  return Text(
                    c.count.toString(),
                    style: const TextStyle(fontSize: 10.0),
                  );
                },
              ),
              foregroundColor: Colors.white,
            ),
            const SizedBox(
              height: 30,
            ),
            RaisedButton(
              child: const Text(
                "Go to Other Page",
                style: TextStyle(
                  fontSize: 20,
                  color: Colors.white,
                ),
              ),
              onPressed: () => Get.to(
                NextScreen(name: "Go to Other Page"),
              ),
            ),
          ],
        ),
      ),
      persistentFooterButtons: [
        RaisedButton(
          child: const Icon(
            Icons.add,
            color: Colors.white,
          ),
          onPressed: () {
            controller.increment(); // 修改state的值
          },
        ),
        RaisedButton(
          child: const Icon(Icons.remove, color: Colors.white),
          onPressed: () {
            controller.decrement(); // 修改state的值
          },
        ),
      ],
    );
  }
}
